package com.yl.module.property.controller;

import com.yl.common.core.domain.Result;
import com.yl.common.core.validate.Group;
import com.yl.module.file.domain.FileType;
import com.yl.module.file.domain.vo.File2VO;
import com.yl.module.file.service.FileService;
import com.yl.module.property.domain.dto.PropertyMaintainAddOrUpdDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import com.yl.module.property.service.PropertyMaintainService;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.yl.module.property.domain.vo.PropertyMaintainVO;
import com.yl.module.property.domain.dto.PropertyMaintainDTO;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 资产保养记录表 Controller控制层
 * @author makejava
 * @date 2024-10-23 15:54:15
 */
@Slf4j
@RestController
@Api(tags = "资产保养记录")
@RequestMapping("/propertyMaintain")
@Validated
public class PropertyMaintainController {
    /**
     * 资产保养记录表 Service
     */
    @Autowired
    public PropertyMaintainService propertyMaintainService;
	@Autowired
    public FileService fileService;

	@PostMapping("file")
	@ApiOperation(value = "资产保养文件上传", notes = "")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "MultipartFile"),
	})
	public Result<File2VO> file(
			@RequestParam(name = "file") MultipartFile file
	) {
		File2VO result = fileService.upload(FileType.TypeEnum.FILE_TYPE_1001.getCode(),file);
		return Result.ok(result);
	}

	@PostMapping("/add")
    @ApiOperation(value = "添加", notes = "")
	public Result<Long> add(
			@RequestBody @Validated(Group.Add.class) PropertyMaintainAddOrUpdDTO dto
	) {
		Long result = propertyMaintainService.add(dto);
		return Result.ok(result);
	}

	@PostMapping("/upd")
    @ApiOperation(value = "通过主键修改", notes = "")
	public Result upd(
			@RequestBody @Validated(Group.Upd.class) PropertyMaintainAddOrUpdDTO dto
	) {
		propertyMaintainService.upd(dto);
		return Result.ok();
	}

	@PostMapping("/del/{id}")
	@ApiOperation(value = "通过id逻辑删除", notes = "")
	public Result del(
			@PathVariable Long id
	) {
		propertyMaintainService.del(id);
		return Result.ok();
	}

}

